//
//  SISSPassengerCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/14.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerCell.h"

@interface SISSPassengerCell ()
@property (weak, nonatomic) IBOutlet UIButton *recommendButton;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;

@end
@implementation SISSPassengerCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
//    	78	150	173
//    self.recommendButton.tintColor = [UIColor yy];
    self.detailLabel.text = @" ";
    // 设置推荐按钮的属性
    self.recommendButton.layer.borderWidth = 1;
    self.recommendButton.layer.borderColor = MAIN_COLOR.CGColor;
    self.recommendButton.layer.cornerRadius = 4;
    self.recommendButton.layer.masksToBounds = YES;
    [self.recommendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self.recommendButton setBackgroundImage:[ImageWithColor imageWithColor:MAIN_COLOR] forState:UIControlStateHighlighted];
}

- (void)setPassengerModel:(SISSPassengerResourceModel *)passengerModel {
    _passengerModel = passengerModel;
    
    UIColor *color = passengerModel.read == 1 ? COLOR(0x8998A5) : COLOR(0x334A60);
    self.nameLabel.textColor = color;
    self.detailLabel.textColor = color;
    
    if (passengerModel.demandType != 2 && passengerModel.name.length != 0 && passengerModel.idNumber.length > 0) {
        
        // 根据身份证判断显示 先生、女士
        NSString *fisrtName = [passengerModel.name substringToIndex:1];
        NSInteger idNum = [[passengerModel.idNumber substringWithRange:NSMakeRange(passengerModel.idNumber.length - 2, 1)] integerValue];
        
        NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
        self.nameLabel.text = [NSString stringWithFormat:@"%@%@  %@",fisrtName,genderStr,@"求购"];
    } else {
        self.nameLabel.text = [NSString stringWithFormat:@"%@  %@",passengerModel.name,@"求购"];
    }
    
    self.detailLabel.text = [NSString stringWithFormat:@"%0.f-%0.f万 | %@-%@ | %@",passengerModel.minPrice,passengerModel.maxPrice,passengerModel.region,passengerModel.regionDetail,passengerModel.houseType];
}

- (void)setButtonTitle:(NSString *)buttonTitle {
    _buttonTitle = buttonTitle;
    
    [self.recommendButton setTitle:buttonTitle forState:UIControlStateNormal];
}

- (void)setIsHideButton:(BOOL)isHideButton {
    _isHideButton = isHideButton;
    self.recommendButton.hidden = isHideButton;
}

/**
 点击推荐房源按钮
 */
- (IBAction)recommendButtonClick:(UIButton *)sender {
    
    // 送出代理
    if ([self.delegate respondsToSelector:@selector(passengerCellRecommendButtonDidClick:)]) {
        
        [self.delegate passengerCellRecommendButtonDidClick:sender];
    }
}

@end
